package Service;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Gr-Developer
 */

import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class ConnectEJB {

    private InitialContext ic;
    private String url;

  public ConnectEJB(String ServerUrl) throws NamingException {
        this.url = ServerUrl;
        if(ic == null){
            this.AddContext();
        }else{
            this.ClearContext();
            this.AddContext();
        }
    }
    private void ClearContext() throws NamingException{
        if(this.ic != null){
            ic.close();
        }
        ic = null;
    }
    private void AddContext() throws NamingException{
        Hashtable<String, String> env = new Hashtable<String, String>(5);
        env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
        env.put(Context.PROVIDER_URL,this.url );
        ic = new InitialContext(env);
    }
    public InitialContext getInitialContext() {
        return ic;
    }

}
